package cn.dnui_xcz826.dnuifood_16110100826.controller;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.List;

import cn.dnui_xcz826.dnuifood_16110100826.R;
import cn.dnui_xcz826.dnuifood_16110100826.adapter.OrderAdapter;
import cn.dnui_xcz826.dnuifood_16110100826.bean.CommentBean;
import cn.dnui_xcz826.dnuifood_16110100826.listener.onRetrofitListener;
import cn.dnui_xcz826.dnuifood_16110100826.model.OrderModel;

public class MyOrderActivity extends BaseActivity implements onRetrofitListener<List<CommentBean>> {
    private RecyclerView myorder_rv;
    private ImageView myorder_return;
    private OrderAdapter adapter;
    public static MyOrderActivity myOrderActivity=null;
    void initViews(){
        setLayout(R.layout.activity_my_order);
        myorder_rv = (RecyclerView)findViewById(R.id.myorder_rv);
        myorder_rv.setLayoutManager(new LinearLayoutManager(MyOrderActivity.this));
        myorder_return = (ImageView)findViewById(R.id.mycomment_return);
    }
    void initEvents(){
        myorder_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    void initDatas() {
        myOrderActivity=this;
        OrderModel orderModel=new OrderModel();
        orderModel.getAllOrdersByUser(getUser_id(),this);
    }

    @Override
    public void onSuccess(List<CommentBean> orderInfos, int flag) {
        adapter = new OrderAdapter(MyOrderActivity.this, orderInfos, R.layout.order_item);
        myorder_rv.setAdapter(adapter);
    }

    @Override
    public void onFailure(String msg) {
        Toast.makeText(MyOrderActivity.this, "错误", Toast.LENGTH_SHORT).show();
    }

}
